home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / e / demos / bigmenu.e < prev    next >
Encoding:
Text File  |  2000-02-28  |  5.9 KB  |  164 lines

  1. /* -- ----------------------------------------------------------------- -- *
  2.  * -- Program.....: BigMenu.e                                           -- *
  3.  * -- Author......: Daniel Kasmeroglu <raptor@cs.tu-berlin.de>          -- *
  4.  * -- Description.: Port of an example bby Henrik Isaksson.             -- *
  5.  * -- ----------------------------------------------------------------- -- *
  6.  * -- Original header:                                                  -- *
  7.  * --                                                                   -- *
  8.  * --   $VER: BigMenu.c 1.6 (05.09.98)                                  -- *
  9.  * --                                                                   -- *
  10.  * --   Popup Menu library test program                                 -- *
  11.  * --                                                                   -- *
  12.  * --   ©1996-1997 Henrik Isaksson                                      -- *
  13.  * --   All Rights Reserved.                                            -- *
  14.  * --                                                                   -- *
  15.  * --   Run and click the mouse in the window!                          -- *
  16.  * --   This little hack is intended to test the submenus.              -- *
  17.  * --                                                                   -- *
  18.  * --   WARNING! When the menu runs out of stack, it will end           -- *
  19.  * --   in a crash!                                                     -- *
  20.  * --                                                                   -- *
  21.  * -- ----------------------------------------------------------------- -- */
  22.  
  23. /* -- ----------------------------------------------------------------- -- *
  24.  * --                              Options                              -- *
  25.  * -- ----------------------------------------------------------------- -- */
  26.  
  27. OPT PREPROCESS       -> enable preprocessor
  28.  
  29.  
  30. /* -- ----------------------------------------------------------------- -- *
  31.  * --                              Modules                              -- *
  32.  * -- ----------------------------------------------------------------- -- */
  33.  
  34. MODULE 'libraries/popupmenu' ,
  35.        'intuition/intuition' ,
  36.        'utility/tagitem'
  37.  
  38. MODULE 'popupmenu'
  39.  
  40.  
  41. /* -- ----------------------------------------------------------------- -- *
  42.  * --                               Main                                -- *
  43.  * -- ----------------------------------------------------------------- -- */
  44.  
  45. ->»» PROC main
  46. PROC main()
  47. DEF ma_window      : PTR TO window
  48. DEF ma_menu        : PTR TO popupmenu
  49. DEF ma_prev        : PTR TO popupmenu
  50. DEF ma_imsg1       : PTR TO intuimessage
  51. DEF ma_imsg2       : intuimessage
  52. DEF ma_bfr [ 50 ]  : STRING
  53. DEF ma_result,ma_i
  54.  
  55.   ma_result := TRUE
  56.   ma_prev   := NIL
  57.  
  58.   popupmenubase := OpenLibrary( 'popupmenu.library', 9 )
  59.   IF popupmenubase <> NIL
  60.  
  61.     ma_prev := PMStartMenu,
  62.                  PMInfo( 'Congratulations!!'     ), PMEnd,
  63.                  PMInfo( 'You\ave shown a great' ), PMEnd,
  64.                  PMInfo( 'deal of patience'      ), PMEnd,
  65.                  PMInfo( 'working your way'      ), PMEnd,
  66.                  PMInfo( 'through all theese'    ), PMEnd,
  67.                  PMInfo( 'menus!'                ), PMEnd,
  68.                  PMInfo( 'You will now be'       ), PMEnd,
  69.                  PMInfo( 'rewarded with a'       ), PMEnd,
  70.                  PMInfo( 'menu option that'      ), PMEnd,
  71.                  PMInfo( 'lets you stop'         ), PMEnd,
  72.                  PMInfo( 'browsing through'      ), PMEnd,
  73.                  PMInfo( 'the menus...'          ), PMEnd,
  74.                  PMBar, PMEnd,
  75.                  PMItem( 'Quit' ), PM_USERDATA, 5, PMEnd,
  76.                End
  77.  
  78.     FOR ma_i := 0 TO 19
  79.  
  80.       StringF( ma_bfr, 'SubMenu #\d', 20 - ma_i )
  81.       ma_prev := PMStartMenu,
  82.                    PMInfo( ma_bfr ), PMEnd,
  83.                    PMItem( 'Next Submenu' ), PM_SUB, ma_prev, PMEnd,
  84.                  End
  85.  
  86.     ENDFOR
  87.  
  88.     -> Create a big menu...
  89.     ma_menu := PMMenu( 'Big Menu' ),
  90.                  PMInfo( 'WARNING: Before you open all' ), PMEnd,
  91.                  PMInfo( 'the submenus, make sure you'  ), PMEnd,
  92.                  PMInfo( 'have enough stack!'           ), PMEnd,
  93.                  PMInfo( 'Set it to at least 10k.'      ), PMEnd,
  94.                  PMBar, PMEnd,
  95.                  PMItem( 'Submenu' ), PM_SUB, ma_prev, PMEnd,
  96.                  PMBar,  End,
  97.                  PMItem( 'Quit'    ), PM_USERDATA, 5, PMEnd,
  98.                End
  99.  
  100.     IF ma_menu <> NIL
  101.  
  102.       -> Open a little window
  103.       ma_window := OpenWindowTagList( NIL,
  104.       [ WA_IDCMP       , IDCMP_CLOSEWINDOW OR IDCMP_MOUSEBUTTONS ,
  105.         WA_RMBTRAP     , TRUE      ,
  106.         WA_DRAGBAR     , TRUE      ,
  107.         WA_WIDTH       , 150       ,
  108.         WA_HEIGHT      , 100       ,
  109.         WA_LEFT        , 150       ,
  110.         WA_TOP         , 0         ,
  111.         WA_TITLE       , 'BigMenu' ,
  112.         WA_CLOSEGADGET , TRUE      ,
  113.         TAG_END ] )
  114.  
  115.       IF ma_window <> NIL
  116.  
  117.         WHILE ma_result <> FALSE
  118.  
  119.           -> Wait for a message
  120.           WaitPort( ma_window.userport )
  121.  
  122.           -> Get the message
  123.           WHILE (ma_imsg1 := GetMsg( ma_window.userport )) <> NIL
  124.  
  125.             CopyMem( ma_imsg1, ma_imsg2, SIZEOF intuimessage )
  126.             ReplyMsg( ma_imsg1 )
  127.  
  128.             IF ma_imsg2.class = IDCMP_CLOSEWINDOW
  129.               ma_result := FALSE
  130.             ELSEIF ma_imsg2.class = IDCMP_MOUSEBUTTONS
  131.  
  132.               ma_result := Pm_OpenPopupMenuA( ma_window,
  133.               [ PM_MENU, ma_menu       ,
  134.                 PM_CODE, ma_imsg2.code , -> Must always be there!
  135.                 TAG_END ] ) - 5
  136.  
  137.             ENDIF
  138.  
  139.           ENDWHILE
  140.  
  141.         ENDWHILE
  142.  
  143.         CloseWindow( ma_window )
  144.  
  145.       ELSE
  146.         PrintF( 'Window error !\n' )
  147.       ENDIF
  148.  
  149.       Pm_FreePopupMenu( ma_menu )
  150.  
  151.     ELSE
  152.       PrintF( 'Menu error !\n' )
  153.     ENDIF
  154.  
  155.     CloseLibrary( popupmenubase )
  156.  
  157.   ELSE
  158.     PrintF( 'Cannot open "popupmenu.library" v9+ !\n' )
  159.   ENDIF
  160.  
  161. ENDPROC
  162. ->»»>
  163.  
  164.